<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jstl - c:forToken</title>
    <style>
        p{
            color:#fff;
            font-size:18px;
            text-align: center;
            width: 180px;
            opacity: .7;
            cursor: pointer;
        }
        /* 控制p标签，奇数样式 */
        p:nth-of-type(odd){
            background-color: #f00;
        }
        p:nth-of-type(even){
            background-color: #00f;
        }

        p:hover{
            opacity: 1.0;
        }
    </style>
</head>

<body>
<%
    //将字符串，设置到pageContext对象属性中，这样EL表达式语句就可以直接使用 ${msg} 读取
    pageContext.setAttribute("msg","java,javascript,mysql,html,vue,jdbc");

    session.setAttribute("user","李四");
    pageContext.setAttribute("user","赵强");
%>
<hr>
${msg}<br>
${pageScope.msg}

${sessionScope.user}
<hr>
<c:forTokens items="${msg}" delims="," var="abc" varStatus="s">
    <h4 style="color:${s.index%2==0 ? 'red' : 'blue'};">${abc}--${s.index}</h4>

    <%--
    <c:if test="${s.index%2==0}">
    <h4 style="color:red;">${abc}--${s.index}</h4>
    </c:if>

    <c:if test="${s.index%2!=0}">
        <h4 style="color:yellow;">${abc}--${s.index}</h4>
    </c:if>
    --%>


</c:forTokens>
</body>
</html>
